<?php
	require_once(dirname(__FILE__)."/../config/dbconfig.php");
	require_once(dirname(__FILE__)."/../config/global.php");
	require_once(dirname(__FILE__)."/../lib/mysql.php");
	require_once(dirname(__FILE__)."/../src/fileSave.php");
	
	ini_set('max_execution_time', '0') ;
	
	
	sql_connect();
	
	$start = 1 ;
	$count = 1 ;
	while($count > 0){
		
		// 处理所有图片或宽度>2000的图片
		//$where = " where `width` > 2000 " ;
		$where = "" ;
		
		$time = date("Ymd H:i:s") ;	
		$filelist = sql_fetch_rows("select * from sys_image $where order by `id` asc limit $start , 100 ") ;
		$getcount = count($filelist) ;
		file_put_contents(dirname(__FILE__)."/change_log.txt","\r\n $time :"."rowcount = $getcount , start = $start ",FILE_APPEND);
		
		$count = 0 ;
		foreach ($filelist as $f){			
			if (file_image_saveas_zoom($f , $f['width'] > 2000 ? 2000 : $f['width']) == 1){
				file_put_contents(dirname(__FILE__)."/change_log.txt","\r\n $time :"."id = {$f['id']} update is ok .",FILE_APPEND);
			}else{
				file_put_contents(dirname(__FILE__)."/change_log.txt","\r\n $time :"."id = {$f['id']} update is error .",FILE_APPEND);
			}
			$count += 1 ;
		}
		$start += 100 ;
	}	
	
	file_put_contents(dirname(__FILE__)."/change_log.txt","\r\n $time :"."process is over .",FILE_APPEND);
	
?>